package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"shop/models"
)

type UserController struct {
	beego.Controller
}

type JsonR struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

func (c *UserController) Login() {
	c.Ctx.Output.Header("Access-Control-Allow-Origin", "*")
	username := c.GetString("name")
	password := c.GetString("password")
	user := models.User{
		Userame:  username,
		Password: password,
	}
	if username != user.Userame || password != user.Password {
		c.Data["json"] = JsonR{
			Code: 500,
			Msg:  "用户名或密码错误",
			Data: nil,
		}
		c.ServeJSON()
		return
	} else {
		c.Data["json"] = JsonR{
			Code: 200,
			Msg:  "登录成功",
			Data: nil,
		}
		c.ServeJSON()
	}
}
